﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Threading;
using WPFExcelReport;
namespace WPFExcelReport
{
    public partial class VABPOS
    {
        public bool IsRun = false;
        /// <summary>
        /// 通过客户0实现不同的组合剪板条件设定。
        /// </summary>
        /// <param name="xdoc"></param>
        public void SaveAB(string ITXDBVERSION, List<DataRow> list)
        {
            //INTEXDBC.StartTransation();
            try
            {
                string KRS = "", LFD = "", POS = "";
                string tbName = "";
                foreach (DataRow row in list)
                {
                    tbName = row.Table.TableName;
                    switch (tbName)
                    {
                        case "ABKOPF":
                            INTEXDBC.SaveABKOPF(row, ITXDBVERSION);
                            break;
                        case "ABPR":
                            INTEXDBC.SaveABPR(row, ITXDBVERSION);
                            break;
                        case "VKPOS":
                            INTEXDBC.UpdateVKPOS(row, ITXDBVERSION);
                            break;
                        case "ABAUFM":
                            INTEXDBC.SaveABAUFM(row, ITXDBVERSION);
                            break;
                        case "ABFOLGE":
                            INTEXDBC.SaveABFOLGE(row, ITXDBVERSION);
                            break;
                        case "ABARTE":
                            INTEXDBC.SaveABARTE(row, ITXDBVERSION);
                            break;
                        case "WDECK":
                            INTEXDBC.SaveWDECK(row, ITXDBVERSION);
                            break;
                        case "BAAUF":
                            INTEXDBC.SaveBAAUF(row, ITXDBVERSION);
                            break;
                        case "GAAUF":
                            INTEXDBC.SaveGAAUF(row, ITXDBVERSION);
                            break;
                        case "BABST":
                            INTEXDBC.SaveBABST(row, ITXDBVERSION);
                            break;
                        case "ZUTEI":
                            INTEXDBC.SaveZUTEI(row, ITXDBVERSION);
                            VGABEW.Instance.NWBBEW(row, "61", "1234");
                            break;
                        case "ICC_ABAX":
                            INTEXDBC.SaveICC_ABAX(row, ITXDBVERSION);
                            break;
                        case "ABPOS":
                            KRS = row["ABPAUFKRS"].ToString();
                            LFD = row["ABPAUFLFD"].ToString();
                            POS = row["ABPAUFPOS"].ToString();
                            EventDispatcher.Instance.RaiseStatus("开始保存 ABPOS:" + KRS + "_" + LFD + "_" + POS, StatusEventType.RunningProgress);
                            INTEXDBC.SaveABPOS(row);
                            break;
                    }
                }
                //INTEXDBC.Commit();
            }
            catch (Exception ex)
            {
                Helpers.LogHelper.error(ex.StackTrace+ex.Message);
                EventDispatcher.Instance.RaiseStatus("分盘出现了网络问题", StatusEventType.StopProgress);

            } 
            EventDispatcher.Instance.RaiseStatus("保存完成", StatusEventType.StopProgress);
        } 
    }
}